﻿using UnityEngine;
using System.Collections;

///<summary>
/// Stupid projectile with forward translation and collision
///</summary>
public class ProjectileBehaviour : Projectile {
    
	// Update is called once per frame
	void Update () 
    {
        //Move the projectile forward
        rigidbody.AddRelativeForce(0f, 0f, speed, ForceMode.Acceleration);
        //The projectile is destroyed if out of range
        if (Vector3.Distance(transform.position, startPosition) > range)
        {
            Destroy(gameObject);
        }
	}

    void OnTriggerEnter(Collider collider)
    {
        //this projectile collides with both air and ground target
        if (collider.gameObject.tag == "Ennemy_ground" || collider.gameObject.tag == "Ennemy_air")
        {
            Destroy(gameObject);
        }
    }
}
